package com.npave.zryhadapter.config;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: common-pathology
 * @description:
 * @author: wj
 * @create: 2023-06-06 15:18
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(AliyunSmsProperties.class)
public class AliyunSmsConfig {

    @Autowired
    private AliyunSmsProperties properties;
    /**
     * 使用AK&SK初始化账号Client
     * @return Client
     * @throws Exception
     */
    @Bean
    public Client createClient() throws Exception {
        Config config = new Config()
                // 必填，您的 AccessKey ID
                .setAccessKeyId(properties.getAccessKeyId())
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret(properties.getAccessKeySecret());
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new Client(config);
    }

}
